<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="所属" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入所属"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="verify">
        <el-select v-model="queryParams.verify" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.shenhezhuangtai"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['flow:export']"
          >导出</el-button
        >
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="createUserId" />
      <el-table-column label="所属" align="center" prop="userName" />
      <el-table-column label="名称" align="center" prop="nickName" />
      <el-table-column width="110" label="电话" align="center" prop="userPhone" />

      <el-table-column label="提现金额" align="center" prop="amount" />

      <el-table-column
        label="提现时间"
        align="center"
        prop="createTime"
        width="180"
      />
      <el-table-column label="审核状态" align="center" prop="verify">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.shenhezhuangtai"
            :value="scope.row.verify"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="审核时间"
        align="center"
        prop="verifyTime"
        width="180"
      />
      <el-table-column label="审核金额" align="center" prop="amount" />
      <el-table-column
        label="驳回原因"
        align="center"
        prop="verifyFail"
        width="180"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            :disabled="scope.row.verify != 0"
            @click="handleUpdates(scope.row)"
            v-hasPermi="['flow:verify']"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="opens"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="forms" :rules="rules" label-width="80px">
        <el-form-item label="审核结果" prop="verify">
          <el-select
            v-model="forms.verify"
            placeholder="审核结果"
            clearable
            @change="outchange"
          >
            <el-option
              v-for="dict in dict.type.shenhe"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <div v-if="isshow == 1">
          <el-form-item label="打款金额" prop="verifyAmount">
            <el-input
              v-model="forms.verifyAmount"
              placeholder="请输入打款金额"
            />
          </el-form-item>
          <el-form-item label="打款截屏" prop="verifyImg">
            <upimg
              :up-with="240"
              :imgSrc="forms.verifyImg"
              :up-height="160"
              :up-bradius="10"
              uptext="请上传打款截屏图片"
              @changeName="imgUrlfun3"
            ></upimg>
          </el-form-item>
        </div>
        <div v-else>
          <el-form-item label="驳回原因" prop="verifyFail">
            <el-input
              v-model="forms.verifyFail"
              type="textarea"
              placeholder="请输入内容"
            />
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPost, verify } from "@/api/system/yue";
import Upimg from "../../../components/UploadImg";

export default {
  components: { Upimg },
  name: "Post",
  dicts: [
    "sys_normal_disable",
    "yuetype",
    "xiadanleixing",
    "zhichuleixing",
    "shenhezhuangtai",
    "shenhe",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      opens: false,
      // 查询参数
      queryParams: {
        flowType: 0,
        consumeType: 1,
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      forms: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" },
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" },
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" },
        ],
      },
      isshow: "",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    outchange(e) {
      this.isshow = e;
    },
    imgUrlfun3(e) {
      if (e) {
        this.forms.verifyImg = e.url;
      } else {
        this.forms.verifyImg = "";
      }
    },
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then((response) => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.opens = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        flowType: "",
        orderId: "",
        orderChannel: "",
        shopId: "",
        shopName: "",
        shopUserName: "",
        shopUserPhone: "",
        consumeType: "",
        verify: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleUpdates(row) {
      const postId = row.postId || this.ids;
      this.opens = true;
      this.forms.id = row.id;
    },
    /** 提交按钮 */
    submitForm: function () {
      console.log(this.forms);
      verify(this.forms).then((response) => {
        this.$modal.msgSuccess("审核成功");
        this.opens = false;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const postIds = row.postId || this.ids;
      this.$modal
        .confirm('是否确认删除岗位编号为"' + postIds + '"的数据项？')
        .then(function () {
          return delPost(postIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/wallet/flow/export",
        {
          ...this.queryParams,
        },
        `流水记录${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
